package com.example.shiro;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.mgt.DefaultSecurityManager;
import org.apache.shiro.subject.Subject;
import org.junit.Before;
import org.junit.Test;

/**
 * @description:
 * @author: guoc
 * @createDate: 2020/5/8 16:36
 */
public class authenticatorTest3 {

    private AbnerRealm abnerRealm=new AbnerRealm();

    private DefaultSecurityManager defaultSecurityManager=new DefaultSecurityManager();

    @Before
    public void init(){
        //环境
        defaultSecurityManager.setRealm(abnerRealm);
        SecurityUtils.setSecurityManager(defaultSecurityManager);
    }

    @Test
    public void testabnerreaml(){
        Subject subject = SecurityUtils.getSubject();
        UsernamePasswordToken usernamePasswordToken=new UsernamePasswordToken("abner","123");
        subject.login(usernamePasswordToken);

        System.out.println(subject.isAuthenticated());
        System.out.println(subject.getPrincipal());

        subject.checkRole("role1");

        System.out.println("是否有对应的角色------->"+subject.hasRole("role1"));
        System.out.println("是否有对应的权限1------->"+subject.isPermitted("video:find"));
        System.out.println("是否有对应的权限2------->"+subject.isPermitted("video:add"));
    }


}
